﻿#ifndef ItemProxy_h__
#define ItemProxy_h__
#include "Global.h"
#include "../vo/DataVO.h"
#include "../../net/NCDefines.h"

//鈼娾垶卤鈭忊墹酶艗陋
enum EquipPart
{
	EQUIP_PART_HELM=0,		//脮鈭懨嘎?
	EQUIP_PART_NECKLACE,	//艙脫隆楼
	EQUIP_PART_WEAPON,		//艗鈥扳垎藴
	EQUIP_PART_CLOTH,		//鈥溌垜藳
	EQUIP_PART_RING,		//惟鈥懊封垙
	EQUIP_PART_SHOES		//鈥撀ㄢ棅鈥?
} ;

//楼聽鈼娾埆驴鈥♀€撁?
enum AffixType
{
	AFFIX_TYPE_ATTACK=0,	//攻击力
	AFFIX_TYPE_DEFENSE,		//防御力
	AFFIX_TYPE_HURT,		//命中
	AFFIX_TYPE_HIT			//伤害
} ;

//楼聽鈼娾埆
struct Affix
{
	AffixType type;
	int value;
    void convert(EquipageExtInfo& info)
    {
        type = (AffixType)info.id;
        value = info.value;
    }
	void convert(Affix* affix)
	{
		type = affix->type;
		value = affix->value;
	}
};

struct ItemInfo
{
    int index;
    int id;
    int count;
    void convert(ItemInfo* info)
    {
        this->id = info->id;
        index = info->index;
        count = info->count;
    }
};

typedef std::vector<Affix*> AffixList;
struct EquipInfo : public ItemInfo
{
    int state;
	int level;
	int exp;
	int atkMin;
	int atkMax;
	int defMin;
    int defMax;
	int life;
	int quality;
    int intensifyNum;
    int intensifyValue;
	AffixList affixs;
    bool isPutOn(){return state == 1;}
    void convert(EquipageInfo& info)
    {
        this->id = info.id;
        index = info.index;
        level = info.level;
        exp = info.exp;
        atkMin = info.atkMin;
        atkMax = info.atkMax;
        defMin = info.def;
        defMax = info.def;
        life = info.life;
        state = info.state;
		affixs.clear();
        std::vector<EquipageExtInfo>& ext = info.ext;
        for(int i = 0; i < ext.size(); i++)
        {
            Affix* affix = new Affix();
            affix->convert(ext[i]);
			affixs.push_back(affix);
        }
    }

	void convert(EquipInfo* info)
	{
		this->id = info->id;
		index = info->index;
		level = info->level;
		exp = info->exp;
		atkMin = info->atkMin;
		atkMax = info->atkMax;
		defMin = info->defMin;
        defMax = info->defMax;
		life = info->life;
		state = info->state;
        intensifyNum = info->intensifyNum;
        intensifyValue = info->intensifyValue;
		affixs.clear();
		std::vector<Affix*> ext = info->affixs;
		for(int i = 0; i < ext.size(); i++)
		{
			Affix* affix = new Affix();
			affix->convert(ext[i]);
			affixs.push_back(affix);
		}
	}

	EquipInfo():quality(0){}
};

struct BagInfo
{
	int bagmax;
	int bagid;
	std::vector<EquipInfo*> equipList;
    void convert(PlayerBagInfo& info)
    {
        bagmax = info.bagmax;
        bagid = info.bagid;
        std::vector<EquipageInfo>& baginfo = info.baginfo;
        for(int i = 0; i < baginfo.size(); i++)
        {
            EquipInfo* equipInfo = new EquipInfo();
            equipInfo->convert(baginfo[i]);
			equipList.push_back(equipInfo);
        }
    }
};

//鈼娾垶卤鈭忊垎鈭懨仿?
enum EquipQuality
{
	EQUIP_QUALITY_WHITE=0,	//鈭炩棅鈼娾垶
	EQUIP_QUALITY_BLUE,		//驴鈭傗棅鈭?
	EQUIP_QUALITY_YELLOW,	//陋鈭嗏棅鈭?
	EQUIP_QUALITY_GOLD,		//惟铮库棅鈭?
	EQUIP_QUALITY_PURPLE,	//鈼娕撯棅鈭?
	EQUIP_QUALITY_ORANGE	//鈮ヂ烩棅鈭?
} ;
typedef std::vector<EquipInfo*> EquipList;
typedef std::vector<ItemInfo*> ItemList;
class ItemProxy : public Singleton<ItemProxy>
{
	void testData();
public:
	ItemProxy();
	~ItemProxy();

	BagInfo bagInfo;
    ItemList itemList;
    int putonIndex;
    vector<int> sellList;

	EquipInfo* lastQiangHuaEquip;
	EquipInfo* curQiangHuaEquip;
	vector<int> mSelectList;

	EquipList& getEquipList();
    ItemList& getItemList();
	void getPutOnList(EquipList& retEquipList);
	void getTakeOffList(EquipList& retEquipList);

	int getBagMax();

	int getBagID();

	//鈮堚€撯垈艙碌驴忙铿偮犅垜脪艗鈩⑩棅鈭灺扁垙
	bool isEquip(int id);

	//鈮堚€撯垈艙鈼娾垶卤鈭徛犅垜脪鈼娾垶卤鈭忊€ε?
	bool isEquipPutOn(int index);

	//鈮堚€撯垈艙鈼娾垶卤鈭徛犅垜脪鈥撯垈艙卢
	bool isEquipTakeOff(int index);

	//碌鈭毬滴┾棅鈭灺扁垙鈮っ概捖?
	EquipPart getEquipPart(int id);

	//楼漏鈥ε撯棅鈭灺扁垙
	void putOnEquip(int index);

	//脮庐蟺藵鈼娾垶卤鈭廼d脮鈥斉撀棅鈭灺扁垙
	void takeOffEquip(int index);

	//脮庐蟺藵鈼娾垶卤鈭忊墹酶艗陋脮鈥斉撀棅鈭灺扁垙
	void takeOffEquip(EquipPart part);
    
    void sellItem(vector<int> sellList);
    
    void removeEquip(int index);
    
    EquipInfo* getEquip(int index);

	int getPutonCount();
	int getEquipCount();

	int getItemCount(int id);

	void clearMergeList();

	void addEquip(std::vector<EquipageInfo>& equipList);
	void addEquip(EquipageInfo& equipageInfo);
	void addEquip(EquipInfo* equipInfo, bool isNew=false);
    
    void addItem(ItemInfo* itemInfo, bool isNew=false);
    ItemInfo* getItem(int index);

    void setLastQiangHuaEquip(EquipInfo* equipInfo);
	void getPropertyValue(EquipInfo* equipInfo, string& ret);
	void getAffixTitle(Affix* affix, string& ret);
	void getAffixValue(Affix* affix, string& ret);
};

#endif // UserProxy_h__